﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Phatent.Website
{
    public class WebContext
    {
        public static HttpContext CurrentContext
        {
            get
            {
                return HttpContext.Current;
            }
            set
            {
                HttpContext.Current = value;
            }
        }

        public static HttpRequest Request
        {
            get
            {
                return CurrentContext.Request;
            }
        }

        public static HttpResponse Response
        {
            get
            {
                return CurrentContext.Response;
            }
        }

        public static string Language
        {
            get
            {
                var language = "zh";
                try
                {
                    var cookie = CurrentContext.Request.Cookies["language"];
                    if (cookie != null)
                    {
                        language = cookie.Value;
                        if (string.IsNullOrEmpty(language))
                            language = "zh";
                    }
                }
                catch { }
                return language;
            }
            set
            {
                if (value != null)
                {
                    var cookie = new HttpCookie("language", value) { Expires = DateTime.Now.AddYears(10) };
                    CurrentContext.Cache["language"] = value;
                    CurrentContext.Response.AppendCookie(cookie);
                }
            }
        }
    }
}
